<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }

        #con {
            background-color: gray;
            height: 1300px;
            position: relative;
            /* margin-left: 100px;
            margin-top: 150px; */
        }

        #adv {
            background-color: aqua;
            width: 100px;
            height: 200px;
            position: absolute;
            top: 100px;
            left: 100px;
            /* overflow: scroll; */
        }
    </style>
</head>

<body>
    <div id="con">

        <div id="adv">
            <a href="javascript:alert(1)">关闭我</a>
            我是广告
            我是广告 我是广告 我是广告 我是广告


        </div>
    </div>
    <script>
        let el = document.getElementById('adv')

        let advOH = el.style.top;
        let advOL = el.offsetLeft;
        console.log(advOH);

        window.addEventListener("scroll", function () {
            let btop = document.documentElement.scrollTop || document.body.scrollTop;
            let leftx = document.documentElement.scrollLeft || document.body.scrollLeft;


            console.log(btop);
            console.log(leftx);
        
            el.style.top =  Number(btop) +100+ 'px';

            let resLeft = Number(advOL) + Number(leftx)
            el.style.left = resLeft + 'px';

            // console.log(el.scrollTop);
            // console.log(el.scrollLeft);

            // console.log(el.offsetHeight);
            // console.log(el.offsetWidth);
        })
    </script>
</body>

</html>